package ch.unisi.inf.pfii.teamred.pacman.controller;

import java.util.Scanner;

import ch.unisi.inf.pfii.teamred.pacman.model.Command;
import ch.unisi.inf.pfii.teamred.pacman.model.Direction;

/**
 * This class describes the interface between the Pacman model and the
 * input/output from/to terminal.
 * 
 * @author luca.vignola@lu.unisi.ch
 * @author mark.pruneri@lu.unisi.ch
 */
public class Console {

	private final Scanner scanner;
	private final Command command;

	public Console() {
		scanner = new Scanner(System.in);
		command = new Command();
	}

	public String readLine() {
		return scanner.nextLine();
	}

	public void writeLine(final String line) {
		System.out.println(line);
	}

	public void write(final String line) {
		System.out.print(line);
	}

	public Direction getDirection() {
		String newDirection = readLine();
		if (newDirection.equals("")) {
			return Direction.NO;
		} else {
			return command.getDirection(newDirection);
		}
	}

}
